package com.hzhr.iot.device.service;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygQuery;
import com.hzhr.iot.core.annotation.CygQuerys;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.device.constant.DeviceOptions;
import com.hzhr.iot.device.constant.DeviceOptionsName;
import com.hzhr.iot.device.constant.DeviceOptionsTypeName;
import com.hzhr.iot.device.constant.Device_ErrorsEnum;
import com.hzhr.iot.device.convertor.custom.DeviceMaintenanceCardCustomConvertor;
import com.hzhr.iot.device.dao.CollectDeviceDao;
import com.hzhr.iot.device.dao.DeviceMaintenanceCardDao;
import com.hzhr.iot.device.entity.DeviceMaintenanceCardEntity;
import com.hzhr.iot.device.entity.ext.CollectDeviceEntityExt;
import com.hzhr.iot.device.entity.ext.DeviceMaintenanceCardEntityExt;
import com.hzhr.iot.device.model.regulatorDevice_maintenanceCard.RegulatorDevice_MaintenanceCardGetModel;
import com.hzhr.iot.device.model.regulatorDevice_maintenanceCard.RegulatorDevice_MaintenanceCardModel;
import com.hzhr.iot.device.model.regulatorDevice_maintenanceCard.RegulatorDevice_MaintenanceCardPostModel;
import com.hzhr.iot.device.queryModel.custom.CollectDeviceCustomQueryModel;
import com.hzhr.iot.device.queryModel.custom.DeviceMaintenanceCardCustomQueryModel;
import com.hzhr.iot.device.service.base.BaseService;
import com.hzhr.iot.login.sdk.model.userCard.UserCardModel;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@CygService(entity = DeviceMaintenanceCardEntity.class, model = RegulatorDevice_MaintenanceCardModel.class)
@CygQuerys({
        @CygQuery(name = "_equal_id", query = "equal_id", type = Integer.class),
        @CygQuery(name = "_equal_year", query = "equal_year", type = String.class),
})
public class RegulatorDevice_MaintenanceCardService extends BaseService{

    @Autowired
    DeviceMaintenanceCardCustomConvertor deviceMaintenanceCardCustomConvertor;

    @Autowired
    DeviceOptions deviceOptions;

    @Autowired
    DeviceMaintenanceCardDao deviceMaintenanceCardDao;

    @Autowired
    CollectDeviceDao collectDeviceDao;
    @Autowired
    RegulatorDevice_MaintenanceCardService regulatorDevice_maintenanceCardService;

    //region javadoc注释 : postByRegulatorDeviceId
    /**
     * 根据调压设备编号创建调压设备的维护卡片 <br/><br/>
     * 简介 : 根据调压设备编号创建调压设备的维护卡片 <br/>
     * 步骤 : <br/>
     * 1. 验证调压设备的存在性 : <br/>
     *  根据路径参数regulatorDeviceId查询采集设备(COLLECT_DEVICE)对象collectDevice_1， <br/>
     *  路径参数筛选规则如下： <br/>
     *  (1) collectDevice_1.id = 路径参数regulatorDeviceId; <br/>
     *  额外筛选规则如下： <br/>
     *  (1) collectDevice_1.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK； <br/>
     *  如果collectDevice_1不存在，抛出异常201 <br/>
     * 2. 验证卡片的存在性 : <br/>
     *  根据body.year和路径参数regulatorBoxId查询设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_1， <br/>
     *  筛选规则如下： <br/>
     *  (1) deviceMaintenance.id = 路径参数regulatorDeviceId； <br/>
     *  (2) deviceMaintenance.year = body.year； <br/>
     *  如果deviceMaintenance_1存在，抛出异常202， <br/>
     * 3. 新增信息卡片 : <br/>
     *  根据body创建设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_2； <br/>
     * 4. 返回信息 : <br/>
     * 创建对象 <br/>
     *  根据条件参数查询修改后的对象deviceMaintenance_2的信息生成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * REGULATORDEVICE_MAINTENANCECARDSERVICE_POST_BY_REGULATOR_DEVICE_ID_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证调压设备的存在性<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 调压设备不存在<br/>
     * REGULATORDEVICE_MAINTENANCECARDSERVICE_POST_BY_REGULATOR_DEVICE_ID_202 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证卡片的存在性<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 本年度的维护卡已存在<br/>
     * @see RegulatorDevice_MaintenanceCardPostModel body <br/>
     * @see RegulatorDevice_MaintenanceCardGetModel result <br/>
     */ 
    //endregion
    //region 说明 : postByRegulatorDeviceId
    //根据调压设备编号创建调压设备的维护卡片
    //简介 : 根据调压设备编号创建调压设备的维护卡片
    //步骤 :
    //1. 验证调压设备的存在性 :
    // 根据路径参数regulatorDeviceId查询采集设备(COLLECT_DEVICE)对象collectDevice_1，
    // 路径参数筛选规则如下：
    // (1) collectDevice_1.id = 路径参数regulatorDeviceId;
    // 额外筛选规则如下：
    // (1) collectDevice_1.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；
    // 如果collectDevice_1不存在，抛出异常201
    //2. 验证卡片的存在性 :
    // 根据body.year和路径参数regulatorBoxId查询设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_1，
    // 筛选规则如下：
    // (1) deviceMaintenance.id = 路径参数regulatorDeviceId；
    // (2) deviceMaintenance.year = body.year；
    // 如果deviceMaintenance_1存在，抛出异常202，
    //3. 新增信息卡片 :
    // 根据body创建设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_2；
    //4. 返回信息 :
    //创建对象
    // 根据条件参数查询修改后的对象deviceMaintenance_2的信息生成结果对象并返回；
    //endregion
    //region 参数 : postByRegulatorDeviceId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "regulatorDeviceId", value = "调压设备编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),


    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : postByRegulatorDeviceId
    @RequestMapping(value = "/regulator-devices/{regulatorDeviceId}/maintenance-cards", method = RequestMethod.POST)
    //endregion
    public RegulatorDevice_MaintenanceCardGetModel postByRegulatorDeviceId(Map<String, String> header, Integer regulatorDeviceId,
                                                                             Map<String, Object> query,
                                                                             RegulatorDevice_MaintenanceCardPostModel body) throws ServiceException {
        //简介 : 根据调压设备编号创建调压设备的维护卡片
        //步骤 :
        //1. 验证调压设备的存在性 :
        // 根据路径参数regulatorDeviceId查询采集设备(COLLECT_DEVICE)对象collectDevice_1，
        // 路径参数筛选规则如下：
        // (1) collectDevice_1.id = 路径参数regulatorDeviceId;
        // 额外筛选规则如下：
        // (1) collectDevice_1.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；
        // 如果collectDevice_1不存在，抛出异常201
        UserCardModel userCard = getUserCard(header);
        CollectDeviceCustomQueryModel queryModel = new CollectDeviceCustomQueryModel();
        queryModel.setEqual_id(regulatorDeviceId);
        queryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        String categoryCode1 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY, DeviceOptionsName.COLLECT_DEVICE_CATEGORY.REGULATOR_BOX);
        String categoryCode2 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY,DeviceOptionsName.COLLECT_DEVICE_CATEGORY.USER_REGULATOR_TANK);
        String categoryCode3 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY,DeviceOptionsName.COLLECT_DEVICE_CATEGORY.SOURCE_REGULATOR_TANK);
        queryModel.setCustom1(categoryCode1);
        queryModel.setCustom2(categoryCode2);
        queryModel.setCustom3(categoryCode3);

        CollectDeviceEntityExt collectDevice_1 = collectDeviceDao.selectExt2(queryModel);
        if (collectDevice_1 == null){ //调压设备不存在
            throw new ServiceException(Device_ErrorsEnum.REGULATORDEVICE_MAINTENANCECARDSERVICE_POST_BY_REGULATOR_DEVICE_ID_201);
        }

        //2. 验证卡片的存在性 :
        // 根据body.year和路径参数regulatorBoxId查询设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_1，
        // 筛选规则如下：
        // (1) deviceMaintenance.deviceId = 路径参数regulatorDeviceId；
        // (2) deviceMaintenance.year = body.year；
        // 如果deviceMaintenance_1存在，抛出异常202，
        DeviceMaintenanceCardCustomQueryModel queryMode2 = new DeviceMaintenanceCardCustomQueryModel();
        queryMode2.setEqual_deviceId(regulatorDeviceId);
        queryMode2.setEqual_year(HzhrTypeUtil.integer2string(body.getYear()));
        queryMode2.setEqual_isValid(CommonOptions.YES_NO.YES);
        DeviceMaintenanceCardEntityExt deviceMaintenance_1 = deviceMaintenanceCardDao.selectExt(queryMode2);
        if (deviceMaintenance_1 != null){
            throw new ServiceException(Device_ErrorsEnum.REGULATORDEVICE_MAINTENANCECARDSERVICE_POST_BY_REGULATOR_DEVICE_ID_202);
        }
        //3. 新增信息卡片 :
        // 根据body创建设备维护卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_2；
        DeviceMaintenanceCardEntity deviceMaintenance_2 = new DeviceMaintenanceCardEntityExt();
        deviceMaintenance_2.setYear(body.getYear().toString());
        deviceMaintenance_2.setDeviceId(regulatorDeviceId);
        deviceMaintenance_2.setCreateTime(new Date());
        deviceMaintenance_2.setIsValid(CommonOptions.YES_NO.YES);
        deviceMaintenance_2.setState("1");
        deviceMaintenance_2.setCreateUserId(userCard.getUserId());
        int changeCount= deviceMaintenanceCardDao.insert(deviceMaintenance_2);

        // 4. 返回信息
        query.put("_equal_id", deviceMaintenance_2.getId());
        RegulatorDevice_MaintenanceCardGetModel result = regulatorDevice_maintenanceCardService.getByRegulatorDeviceId(initHeader(header, AccessModeEnum.GLOBAL), regulatorDeviceId, query);
        result.setChangeCount(changeCount);
        return result;
    }

    //region javadoc注释 : getByRegulatorDeviceId
    /**
     * 根据调压设备编号查询调压设备的维护卡片 <br/><br/>
     * 简介 : 根据调压设备编号查询调压设备的维护卡片 <br/>
     * 步骤 : <br/>
     * 1. 查询维护卡片 : <br/>
     *  根据条件参数和路径参数regulatorDeviceId查询DEVICE_MAINTENANCE_CARD对象集合deviceMaintenanceList_1， <br/>
     *  路径参数的筛选规则如下： <br/>
     *  (1) deviceMaintenanceList_1[i].deviceId = 路径参数regulatorDeviceId； <br/>
     *  额外的筛选条件如下： <br/>
     *  (2) deviceMaintenanceList_1[i]..deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK； <br/>
     * 2. 返回信息 : <br/>
     *  根据deviceMaintenanceList_1及条件参数生成结果对象并返回; <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _is_paging : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否分页;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where RegulatorDevice_MaintenanceCardModel.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_year : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where RegulatorDevice_MaintenanceCardModel.year = #{_equal_year};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see RegulatorDevice_MaintenanceCardGetModel result <br/>
     */ 
    //endregion
    //region 说明 : getByRegulatorDeviceId
    //根据调压设备编号查询调压设备的维护卡片
    //简介 : 根据调压设备编号查询调压设备的维护卡片
    //步骤 :
    //1. 查询维护卡片 :
    // 根据条件参数和路径参数regulatorDeviceId查询DEVICE_MAINTENANCE_CARD对象集合deviceMaintenanceList_1，
    // 路径参数的筛选规则如下：
    // (1) deviceMaintenanceList_1[i].deviceId = 路径参数regulatorDeviceId；
    // 额外的筛选条件如下：
    // (2) deviceMaintenanceList_1[i]..deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；
    //2. 返回信息 :
    // 根据deviceMaintenanceList_1及条件参数生成结果对象并返回;
    //endregion
    //region 参数 : getByRegulatorDeviceId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "regulatorDeviceId", value = "调压设备编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_year", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.year = #{equal_year}",required = false, dataType = "string", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_year", value = "筛选条件 : where RegulatorDevice_MaintenanceCardModel.year = #{_equal_year}",required = false, dataType = "string", paramType = "query"),

    })
    //endregion
    //region 请求 : getByRegulatorDeviceId
    @RequestMapping(value = "/regulator-devices/{regulatorDeviceId}/maintenance-cards", method = RequestMethod.GET)
    //endregion
    public RegulatorDevice_MaintenanceCardGetModel getByRegulatorDeviceId(Map<String, String> header, Integer regulatorDeviceId,
                                                                                Map<String, Object> query) throws ServiceException {

        /* 查询维护卡片 */
        DeviceMaintenanceCardCustomQueryModel queryModel = deviceMaintenanceCardCustomConvertor.regulatorDevice_MaintenanceCardService_query2queryModel(query);
        queryModel.setEqual_deviceId(regulatorDeviceId);
        String categoryCode1 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY, DeviceOptionsName.COLLECT_DEVICE_CATEGORY.REGULATOR_BOX);
        String categoryCode2 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY,DeviceOptionsName.COLLECT_DEVICE_CATEGORY.USER_REGULATOR_TANK);
        String categoryCode3 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY,DeviceOptionsName.COLLECT_DEVICE_CATEGORY.SOURCE_REGULATOR_TANK);
        queryModel.setCustom1(categoryCode1);
        queryModel.setCustom2(categoryCode2);
        queryModel.setCustom3(categoryCode3);
        if (categoryCode1 != null && categoryCode2 != null && categoryCode3 != null) {
            queryModel.setExt_deviceExt(true);
        }
        List<DeviceMaintenanceCardEntityExt> deviceMaintenanceList_1 = null;
        if (!StringUtils.isEmpty(query.get("_show"))) {
            deviceMaintenanceList_1 = deviceMaintenanceCardDao.selectExtList1(queryModel);
        }
        Boolean showTotal = HzhrTypeUtil.object2boolean(query.get("_show_total"));
        Integer count = null;
        if (showTotal != null && showTotal) {
            count = deviceMaintenanceCardDao.selectCount(queryModel);
        }

        //2. 返回信息 :
        // 根据deviceMaintenance_1对象及条件参数生成结果对象并返回;
        RegulatorDevice_MaintenanceCardGetModel result = deviceMaintenanceCardCustomConvertor.extList2regulatorDevice_MaintenanceCardGetModel(deviceMaintenanceList_1, count,null,query);
        return result;
    }
}

